# @shuaige : 陈世玉
# @name :nameData.py
# @time :2024/12/13 16:26
import pymysql
from pyecharts.charts import Pie
import pyecharts.options as opts

#连接数据库
conn=pymysql.connect(
            host="localhost",
            port=3306,user="root",
            password="17884873770",
            database="spider01",
            charset="utf8")
cursor=conn.cursor()
sql="select name,count(*) from data group by name"
cursor.execute(sql)
result=cursor.fetchall()
result=list(result)
name=[]
count=[]
for i in range(len(result)):
    name.append(result[i][0])
    count.append(result[i][1])
print(name)
print(count)
pie = (
    Pie(init_opts=opts.InitOpts(width='1500px', height='900px'))
    .add(series_name='', data_pair=[(i, j) for i, j in zip(name, count)])
    .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}:{c}"))
)

pie.render('nameData.html')

